package com.xiaoyun;

import com.xiaoyun.service.someService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Date;

public class mytest {
    @Test
    public void test01(){
        String config = "beans.xml";

        //ApplicationContext表示spring容器  ，获取对象

        //从类路径加载配置文件
        ApplicationContext ac = new ClassPathXmlApplicationContext(config);

        //spring默认创建对象的时间是 创建spring容器时创建对象
        someService  someservice = (someService) ac.getBean("someService");
        someservice.dosome();
    }

    @Test
    public void test02(){
        ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
        int num = ac.getBeanDefinitionCount();
        System.out.println("对象数量: "+num);
        String names[] = ac.getBeanDefinitionNames();
        for(String name:names){
            System.out.println(name);
        }
    }

    @Test
    public void test03(){

        //spring创建对象默认调用无参构造方法
        ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
        Date date = (Date) ac.getBean("mydate");
        System.out.println(date);
    }
}
